#include "ActionSleep.h"
#include "Steering.h"
#include "World.h"
#include "Hostility.h"

ActionSleep::ActionSleep()
{
	executer__=0;
	sleepingTime__=0;
}


ActionSleep::~ActionSleep()
{
}

bool ActionSleep::execute(Entity* executer)
{
	executer__ = executer ;
	NPCEntity * realExecuter = dynamic_cast<NPCEntity *>(executer) ;
	
	sleepingTime__+=World::getWorld()->elapsedTime();

	//put the animation of the frog at "Stand"
	realExecuter->setAnimation(EMAT_STAND);
	//we add life during the Entity is sleeping
	realExecuter->addLife(5*World::getWorld()->elapsedTime());
	
	//the plan is finish if the Entity is sleeping sinces 4s or if his life is max 
	if(sleepingTime__>4 || realExecuter->getLife()==realExecuter->getLife().getMax())
		return true;
	else
		return false;


	if(debug[Debug::PLAN_INFO])
		std::cout << "Sleeping" << std::endl ;

}

bool ActionSleep::checkConditions()
{
	if(executer__ != 0)
	{	
		//the plan is interupted if the Entity is under attack
		NPCEntity * realExecuter = dynamic_cast<NPCEntity *>(executer__) ;
		if(realExecuter->isUnderAttack())
			return false;
	}
	return true ;
}
 
